package meterMonitor.controller;

import meterMonitor.biz.MonitorExceptionLogBiz;
import meterMonitor.consts.ResponseCode;
import meterMonitor.model.Meter;
import meterMonitor.model.MonitorExceptionLog;
import meterMonitor.vo.BaseResponseData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@RequestMapping("exception")
@RestController
public class ExceptionController {
    public static final Logger logger = LoggerFactory.getLogger(WaterChartController.class);

    @Autowired
    MonitorExceptionLogBiz monitorExceptionLogBiz;

    /**
     * 异常管理页面
     *
     * @param mv
     * @return
     */
    @RequestMapping("exceptionIndex.do")
    public ModelAndView index(ModelAndView mv) {
        return mv;
    }

    /**
     * 查询异常信息
     *
     * @param monitorExceptionLog
     */
    @RequestMapping("queryAll.do")
    public BaseResponseData queryAll(MonitorExceptionLog monitorExceptionLog) {
        BaseResponseData response = new BaseResponseData();
        try {

            List<MonitorExceptionLog> datas = monitorExceptionLogBiz.query(monitorExceptionLog);
            response.setCode(ResponseCode.SUCCESS);
            response.setData(datas);
        } catch (Exception e) {
            logger.error("查询异常信息失败！", e);
            response.setCode(ResponseCode.DATA_EXCEPTION);
            response.setMessage("查询异常信息失败！");
        }
        return response;
    }

    /**
     * 更新异常信息
     *
     * @param monitorExceptionLog
     */
    @RequestMapping("updateRemark.do")
    public BaseResponseData updateRemark(MonitorExceptionLog monitorExceptionLog) {
        BaseResponseData response = new BaseResponseData();
        try {
            monitorExceptionLogBiz.updateRemark(monitorExceptionLog);
            response.setCode(ResponseCode.SUCCESS);
        } catch (Exception e) {
            logger.error("更新异常信息失败！", e);
            response.setCode(ResponseCode.DATA_EXCEPTION);
            response.setMessage("更新异常信息失败！");
        }
        return response;
    }
}
